package oom;

import java.util.ArrayList;
import java.util.List;

public class MethodAreaOOM {
    /**
     * jdk6 字符串常量池在方法区（持久代 PermGen） Permanent Generation;
     * Args：-XX:PermSize=6M -XX:MaxPermSize=6M
     * java -XX:PermSize=6M -XX:MaxPermSize=6M oom.MethodAreaOOM
     * Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
     *
     * jdk7 threshold
     * -XX:MaxMetaspaceSize=256m
     * java -Xms5m -Xmx5m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=D:/logs oom.MethodAreaOOM
     * -XX:+PrintStringTableStatistics
     * -verbose:gc
     * -XX:+PrintGCDetails
     * Enables printing of detailed messages at every GC. By default, this option is disabled.
     * @param args
     */
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        long i=0;
        while (true) {
            String a = new String("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf"+i);
//            list.add(a.intern());
            a.intern();
            i++;
            if (i > 6000) {
                break;
            }
        }
    }
}
